// ============================================================================
//
// Copyright (C) 2009-2011 SC Technology Group. - www.sc.com
//
// ============================================================================
package com.cs.vessel.breakdown.wizards;

import java.util.Iterator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.cs.vessel.breakdown.CDOHibernateUtil;
import com.ibm.team.jface.ConfigComposite;
import com.sc.vessel.info.model.breakdown.BreakdownFactory;
import com.sc.vessel.info.model.breakdown.ConfigElement;
import com.sc.vessel.info.model.breakdown.ConfigElementSelected;
import com.sc.vessel.info.model.breakdown.Configuration;

/**
 * DOC liaoqc class global comment. Detailled comment
 */
public class AccidentWizardSecondPage extends WizardPage {

    /**
     * DOC liaoqc AccidentWizardSecondPage constructor comment.
     * 
     * @param pageName
     */
    protected AccidentWizardSecondPage(String pageName) {
        super(pageName);
        setTitle(Messages.AccidentWizardSecondPage_0);
        setDescription(Messages.AccidentWizardSecondPage_1);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createControl(Composite parent) {
        final AccidentNewWizard wizard = (AccidentNewWizard) getWizard();
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout());
        composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));

        Configuration configuration = CDOHibernateUtil.getConfiguration();
        EList<ConfigElement> configElements = configuration.getElements();
        for (Iterator<ConfigElement> iterator = configElements.iterator(); iterator.hasNext();) {
            ConfigElement configElement = (ConfigElement) iterator.next();
            ConfigElementSelected configElementSelected = BreakdownFactory.eINSTANCE.createConfigElementSelected();
            configElementSelected.setConfigElement(configElement);
            wizard.getAccident().getConfigElements().add(configElementSelected);
            ConfigComposite configComposite = new ConfigComposite(composite, SWT.NONE, configElement, configElementSelected);
            // configComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
            configComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
            // configComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
        }
        setControl(composite);
    }

}
